package com.bluesky.plum.richdomain;

import java.util.Set;

import com.bluesky.plum.validate.validator.Validator;

public class RichDomainField implements Comparable<RichDomainField> {

	public Object value;

	public Class fieldClass;
	public Class elementClass;// if fieldClass is a collection
								// class(List,Array,Set,Map)
	public FieldType fieldType;

	// common
	public String name;
	public Boolean nullable;

	public boolean enabled;

	// Persist specific

	// UI specific
	public String caption;
	public String description;
	
	public int position;
	
	public Set<Validator> validators;

	// AdvancedAttributes advancedAttributes;
	/**
	 * if the target UI component type is forced,
	 */
	public UIComponentAttributes uiComponentAttributes;

	@Override
	public String toString() {
		return String.format("%s", name);
	}

	public void copy(RichDomainField src) {
		value = src.value;

		fieldClass = src.fieldClass;
		elementClass = src.elementClass;// if fieldClass is a collection
										// class(List,Array,Set,Map)
		fieldType = src.fieldType;

		// common
		name = src.name;
		nullable = src.nullable;

		enabled = src.enabled;

		// Persist specific

		// UI specific
		caption = src.caption;
		description = src.description;
		position = src.position;
	}

	@Override
	public int compareTo(RichDomainField o) {
		//System.out.println("compareTo:"+o);
		int r = position - o.position;
		if(r!=0)
			return r;
		
		//else compare the name, and they must not be same
		return name.compareTo(o.name);
		
		
	}
}
